package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.mvp.contract.BindAlipayContract;
import com.qf.flash.utils.LogUtil;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.exception.ApiException;
import com.qf.flashlib.util.RxUtils;

public class BindAlipayPresenter extends BasePresenter<BindAlipayContract.View> implements BindAlipayContract.Presenter {
    String uid = UserMgr.getInstance().getLoginUser().getUid();
    @Override
    public void bindAlipay(String mobile, String bankCard, String userName,String code) {

        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .BIND_ZFB(uid,mobile,bankCard,userName,code)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<Object>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<Object> objectBaseResponse) {
                        LogUtil.d("ApiException:" + objectBaseResponse.getMsg());
                        mRootView.finished();
                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                        LogUtil.d("ApiException:" + e.getMessage());
                    }
                })
        );

    }

    @Override
    public void unBindAlipay(String bankId, String code) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .UNBIND_ZFB(uid,bankId,code)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<Object>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<Object> objectBaseResponse) {
                        LogUtil.d("ApiException:" + objectBaseResponse.getMsg());
                        mRootView.finished();
                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                        LogUtil.d("ApiException:" + e.getMessage());
                    }
                })
        );


    }


}
